/** 
 * @file: example.c
 * @author: chen <ischen.x@outlook.com>
 * @brief: You can define the macro multi_click_enable in mlib_key.h to enable the detection of multiple-click 
 *         events (enabled by default), or leave it undefined to disable it and reduce resource 
 *         usage. Additionally, you can increase the sensitivity of single-click event scanning.
 * @data: 2024/02/02
 * @version: V1.0
 */
#include "mlib_key.h"

enum key_id{
	user_key_id_0,
	user_key_id_1,
	user_key_id_2,
};

Button user_key_0, user_key_1, user_key_2;

uint8_t get_gpio_input(uint8_t btn_id)
{
	switch (btn_id)
	{
		case user_key_id_0:
			return gpio_input_bit_get(GPIOA, GPIO_PIN_0);
		case user_key_id_1:
			return gpio_input_bit_get(GPIOA, GPIO_PIN_1);
		default:
			return 0;
	}
}

/**
 * @brief Callback function for key event triggering.
 * @param btn 
 */
void btn_cb1(Button *btn)
{
	printf("SINGLE_CLICK\r\n");
}

void btn_cb2(Button *btn)
{
	printf("MULTI_CLICK->id: %d    EVENT:%d , click count:%d\r\n", btn->id, btn->event, btn->trigger_times);
}

void btn_cb3(Button *btn)
{
	printf("id: %d    EVENT:%d \r\n", btn->id, btn->event);
}

/**
 * @brief Initialize the key driver.
 */
void bsp_key_init(void)
{
    keys_gpio_init();
	
	btn_set_get_gpio_input_fun(get_gpio_input);
	btn_init(&user_key_0, user_key_id_0, 1);
	btn_init(&user_key_1, user_key_id_1, 0);
	btn_set_callback(&user_key_0, SINGLE_CLICK, btn_cb1);
	btn_set_callback(&user_key_0, DOUBLE_CLICK, btn_cb2);
	btn_set_callback(&user_key_0, MULTI_CLICK, btn_cb2);
	btn_set_callback(&user_key_0, LONG_PRESS, btn_cb3);
	btn_set_callback(&user_key_1, SINGLE_CLICK, btn_cb1);
	btn_set_callback(&user_key_1, DOUBLE_CLICK, btn_cb2);
	btn_set_callback(&user_key_1, MULTI_CLICK, btn_cb2);
	btn_set_callback(&user_key_1, LONG_PRESS, btn_cb3);
}

/**
 * @brief Call the button_scan() every 5 milliseconds.
 */
int main()
{
    button_scan();
    sleep(500);
}


